import 'package:android_intent_plus/android_intent.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../AppConfig/Config.dart';
import '../../AppConfig/ShowDialog.dart';
import '../../l10n/messages.dart';
import 'package:platform/platform.dart';
class EvaluationDetails extends StatefulWidget {
  const EvaluationDetails({super.key, required this.dataMap});
  final Map dataMap;
  @override
  State<EvaluationDetails> createState() => _EvaluationDetailsState();
}

class _EvaluationDetailsState extends State<EvaluationDetails> {

  @override

  _makePhoneCall(String phoneNumber) async {
    if (LocalPlatform().isAndroid) {
      var status = await Permission.phone.status;
      if (status.isGranted) {
        // 权限已被授予
        // callPhone();
        final AndroidIntent intent = AndroidIntent(
          action: 'android.intent.action.CALL',
          data: Uri.encodeFull('tel:$phoneNumber'),
        );
        await intent.launch();
      } else if (status.isDenied) {
        // 权限被拒绝，但用户可以再次授权
        showCallPhoneFirstDialog(context);
        status = await Permission.phone.request();
        if (status.isGranted) {
          // 用户同意了权限
          // callPhone();
          final AndroidIntent intent = AndroidIntent(
            action: 'android.intent.action.CALL',
            data: Uri.encodeFull('tel:$phoneNumber'),
          );
          await intent.launch();
        } else {
          showCallPhoneDialog(context);
          // 用户拒绝权限，无法发起电话
          // 可以在此处展示信息提示用户需要权限
        }
      } else if (status.isPermanentlyDenied) {
        // 权限被永久拒绝，需要用户手动开启权限
        showCallPhoneDialog(context);
      }

    }else{
      final url =Uri.parse('tel:$phoneNumber');
      if (await canLaunchUrl(url)) {
        await launchUrl(url);
      } else {
        throw '无法拨打电话：$url';
      }
    }
  }
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor: Colors.white,
        leading: IconButton(icon: Icon(Icons.arrow_back_ios,color: Colors.black,),onPressed: (){Navigator.pop(context);},),
        centerTitle: true,
        title: Text("评价详情",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
      ),
      body: ListView(
        children: [

          Container(
            margin: EdgeInsets.only(left: 8.w,right: 8.w,top: 8.h),
            padding: EdgeInsets.only(left: 8.w,right: 8.w,top: 10.h,bottom: 10.h),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(10)),
             // 边框宽度
              ),
            child: Row(
              children: [
                SizedBox(width: 8.w,),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        Text(widget.dataMap['route'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),

                      ],
                    ),
                    Text(widget.dataMap['createTime'],style: TextStyle(color: MyColors.hintColor,fontSize: 12.sp),),
                  ],
                ),
                SizedBox(width: screenSize.width/6,),
                GestureDetector(
                  child: Image.asset("lib/Images/OrderList/电话联系icon.png",width: 25.w,height: 25.h,),
                  onTap: (){
                    _makePhoneCall('1234567890');
                  },
                ),
              ],
            ),
            ),
          Container(
            margin: EdgeInsets.only(left: 8.w,right: 8.w),

            height: 29.h,
            decoration: BoxDecoration(
              color: Color.fromRGBO(239, 239, 239, 1),
              borderRadius: BorderRadius.only(bottomLeft:Radius.circular(5) ,bottomRight: Radius.circular(5)),
              // 边框宽度
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                TextButton(onPressed: (){

                },
                    child: Text("查看详情 >",style: TextStyle(color: Colors.black,fontSize: 12.sp),)),
              ],
            ),
          ),

          Container(
            margin: EdgeInsets.only(left: 8.w,right: 8.w,top:8.h),
            height: 114.h,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(5)),
              // 边框宽度
            ),
            child: Column(
              children: [
                Row(
                  children: [
                    SizedBox(width: 18.w,),
                    Image.asset("lib/Images/PersonCenter/评价详情bookmark.png",width: 18.w,height: 18.h,),
                  ],
                ),
                Center(
                  child: Text("他对我的评价",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600),),
                ),
                SizedBox(height: 10.h,),
                Center(
                  child:  Image.asset("lib/Images/PersonCenter/好评彩色.png",width: 33.w,height: 33.h,),
                ),
                Center(
                  child: Text("好评",style: TextStyle(color: MyColors.themeColor),),
                ),

              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: 8.w,right: 8.w,top:8.h),
            height: 134.h,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(5)),
              // 边框宽度
            ),
            child: Column(
              children: [
              SizedBox(height: 20.h,),
                Center(
                  child: Text("我对他的评价",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600),),
                ),
                SizedBox(height: 10.h,),
                Center(
                  child:  Image.asset("lib/Images/PersonCenter/好评彩色.png",width: 33.w,height: 33.h,),
                ),
                Center(
                  child: Text("好评",style: TextStyle(color: MyColors.themeColor),),
                ),
                SizedBox(height: 8.h,),
            Row(
              children: [
                SizedBox(width: 8.w,),

                Container(

                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                    border: Border.all(
                      color: MyColors.themeColor, // 边框颜色
                      width: 1.0, // 边框宽度
                    ),
                  ),

                  child: Center(
                    child: Text("认证负责",style: TextStyle(color: MyColors.themeColor,fontSize:10.sp ),),
                  ),
                  height: 20.h,
                  width: 54.w,
                ),
              ],
            )
              ],
            ),
          ),

        ],
      ),
    );
  }
}
